"""
测试财务添加应付款点击保存并新建
"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

#打开浏览器
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(30)
#打开crm
driver.get("http://192.168.1.25/crm")
sleep(1)
#准备数据
username = "admin"
password = "123456"
yfk_name = "keke"
fkje = "666"
#定位器
username_locator = (By.NAME,'name')
password_locator = (By.NAME,'password')
login_btn_locator = (By.NAME,'submit')
cw_locator = (By.LINK_TEXT,'财务')
yfk_btn_locator = (By.LINK_TEXT,'应付款')
xj_yfk_locator = (By.CSS_SELECTOR,'body > div.container > div.row > div:nth-child(1) > div.pull-right > a:nth-child(1)')
yfk_name_locator = (By.NAME,'name')
kh_name_locator = (By.NAME,'customer')
xzkh_locator =(By.CSS_SELECTOR,'input[value="3"]')
kh_btn_locator =(By.CSS_SELECTOR,'body > div:nth-child(8) > div.ui-dialog-buttonpane.ui-widget-content.ui-helper-clearfix > div > button:nth-child(1) > span')
fkje_locator = (By.NAME,'price')
yfk_bcxj_btn_locator =(By.NAME,'submit')


#登录输入用户名和密码
driver.find_element(*username_locator).send_keys(username)
driver.find_element(*password_locator).send_keys(password)
sleep(1)
#点击登录
driver.find_element(*login_btn_locator).click()
sleep(1)
#点击财务
driver.find_element(*cw_locator).click()
sleep(1)
#点击应付款
driver.find_element(*yfk_btn_locator).click()
#点击新建
driver.find_element(*xj_yfk_locator).click()
sleep(1)
#输入应付款名
driver.find_element(*yfk_name_locator).send_keys(yfk_name)
sleep(1)
#选择客户
driver.find_element(*kh_name_locator).click()
sleep(1)
driver.find_element(*xzkh_locator).click()
sleep(1)
#点击客户确定按钮
driver.find_element(*kh_btn_locator).click()
sleep(1)
#输入付款金额
driver.find_element(*fkje_locator).send_keys(fkje)
#点击保存并新建
driver.find_element(*yfk_bcxj_btn_locator).click()
sleep(1)


driver.quit()